<cfsetting enablecfoutputonly="Yes">
<!---
	where/lookup.cfm
--->

<cfcontent type="application/xml">

<cfset CrLf=Chr(13) & Chr(10)>
<cfset Tab=Chr(9)>

<cftry>
	<cfparam name="Form.v" type="string" default="1">
	<cfparam name="Form.LID" type="string" default="">
	<cfset APIver=Form.v>
	<cfif not isNumeric(APIver)><cfset APIver=1></cfif>
	<cfset n=0>
	<cfset places=queryNew("lat,lng,title,n")>
	<cfloop condition="structKeyExists(Form, 'lat' & n) or structKeyExists(URL, 'lat' & n)">
		<cfset queryAddRow(places)>
		<cfloop list="#places.columnList#" index="colName">
			<cfif structKeyExists(Form, colName & n)>
				<cfset querySetCell(places, colName, Trim(Form[colName & n]), places.RecordCount)>
			<cfelseif structKeyExists(URL, colName & n)>
				<cfset querySetCell(places, colName, Trim(URL[colName & n]), places.RecordCount)>
			</cfif>
			<cfset querySetCell(places, "n", n, places.RecordCount)>
		</cfloop>
		<cfset n=n+1>
	</cfloop>
	<!--- <cfdump var="#places#"> --->
	<cfset places2=queryNew(places.columnList)>
	<cfloop query="places">
		<cfif isNumeric(lat) and isNumeric(lng) and (lat gte -90) and (lat lte 90) and (lng gte -180) and (lng lte 180) and (title neq "")>
			<cfset queryAddRow(places2)>
			<cfset querySetCell(places2, "n", n, places2.recordCount)>
			<cfset querySetCell(places2, "lat", int(lat*1000000), places2.recordCount)>
			<cfset querySetCell(places2, "lng", int(lng*1000000), places2.recordCount)>
			<cfset querySetCell(places2, "title", left(title,64), places2.recordCount)>
		</cfif>
	</cfloop>
	<cfoutput><places key="#Session.GeoKey#" lid="#XMLFormat(Form.lid)#"></cfoutput>
	<cfif places2.recordCount gt 0>
		<cfquery datasource="nowrists2007" name="FindPlaces">
		<cfloop query="Places2">
		<cfif currentRow gt 1>UNION ALL</cfif>
		SELECT
			<cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#n#"> AS n,
			WiFiFree, WiFiPaid, FoodDrinks, FoodSolid, Outlets, OpenUntil, Days
		FROM nws_places
		WHERE (lat = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#lat#">)
		  AND (lng = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="#lng#">)
		  AND (title = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#title#">)
		</cfloop>
		</cfquery>
		<!--- <cfdump var="#places2#"> --->
		<cfset lastCol=listLast(FindPlaces.columnList)>
		<cfoutput query="FindPlaces"><place <cfloop list="#FindPLaces.columnList#" index="colName"> #LCase(colName)#="#XMLFormat(FindPlaces[colName][currentRow])#"</cfloop>/></cfoutput>
	</cfif>
	<cfoutput></places></cfoutput>
<cfcatch>
	<cfoutput><error>#XMLFormat(CFCatch.Message)#"</error></cfoutput>
</cfcatch>
</cftry>

<cfsetting enablecfoutputonly="No">